package org.lemon.transport.context.service.queue.stats;

import io.micrometer.core.instrument.Counter;

import java.util.concurrent.atomic.AtomicInteger;

public class StatsCounter {

    private final String name;
    private final AtomicInteger counter;
    private final Counter micrometerCounter;

    public StatsCounter(String name, AtomicInteger counter, Counter micrometerCounter) {
        this.name = name;
        this.counter = counter;
        this.micrometerCounter = micrometerCounter;
    }

    public void increment() {
        counter.incrementAndGet();
        micrometerCounter.increment();
    }

    public void clear() {
        counter.set(0);
    }

    public int get() {
        return counter.get();
    }

    public void add(int delta) {
        counter.addAndGet(delta);
        micrometerCounter.increment(delta);
    }
}
